<template>
  <cl-dialog title="新增财务明细" width="450px" :visible.sync="visible" :before-close="beforeClose" @close="close" :props="{
    top: '10vh',
    appendToBody: true,
    closeOnClickModal: false
  }">
    <el-form ref="form" :model="form" :rules="rules" label-position="top" :disabled="saving">
      <el-form-item label="日期" prop="appoint_date">
        <el-date-picker v-model="form.appoint_date" type="date" value-format="yyyy-MM-dd" placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item style="width: 100%;" label="门店" prop="dept_id">
        <cl-shop-select v-model="form.dept_id" filterable clearable :biz_id="biz_id" style="width: 100%" />
      </el-form-item>
      <el-form-item style="width: 100%;" label="应收金额（应付金额）" prop="debt">
        <el-input v-model="form.debt"></el-input>
      </el-form-item>
      <el-form-item style="width: 100%;" label="订单号" prop="order_no">
        <el-input v-model="form.order_no"></el-input>
      </el-form-item>
      <!-- <el-form-item label="收款方" prop="payee">
        <cl-select clearable v-model="form.payee" style="width: 100%">
          <el-option :value="2" label="院方" />
          <el-option :value="1" label="我方" />
        </cl-select>
      </el-form-item> -->
      <el-form-item style="width: 100%;" label="备注">
        <el-input v-model="form.remark"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="close">关闭</el-button>
      <el-button type="primary" @click="submit" :loading="saving">确定</el-button>
    </template>
  </cl-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      saving: false,
      order_no: null,
      form: {},
      rules: {
        appoint_date: [{ required: true, message: "日期必填" }],
        dept_id: [{ required: true, message: "门店必填" }],
        debt: [{ required: true, message: "应返款/应收款必填" }],
      }, biz_id: null
    };
  },
  methods: {
    open(data = {}) {
      this.visible = true;
      this.form = data;
      this.biz_id = this.getCurrBiz();
    },
    submit() {
      this.$refs.form.validate(async (valid, errors) => {
        if (!valid) return;
        try {
          this.saving = true;
          console.log(this.form);
          await this.$service.reconciliation.orderAdd(this.form);
          this.$message.success("操作成功");
          this.$emit("successed");
          this.saving = false;
          this.close();
        } catch (error) {
          this.saving = false;
        }
      });
    },
    beforeClose(done) {
      if (this.saving) return;
      done();
    },
    close() {
      if (this.saving) return;
      this.visible = false;
      this.reset();
    },
    reset() {
      this.saving = false;
      this.$refs.form.resetFields();
    }
    //获取人员
  }
};
</script>

<style lang="scss" scoped>
::v-deep {
  .el-radio {
    margin-bottom: 10px !important;
  }
}
</style>
